Imports System.Text

Public Class CSDOCollectionRenderEngine
    Inherits CSAbstractRenderEngine

    Public Sub New(ByVal u As UpdateProgress, ByVal s As UpdateStatus)
        MyBase.New(u, s, GetType(SQL))
    End Sub

    Protected Overrides Function FormatFilename(ByVal tableName As String) As String
        Return tableName & "Collection"
    End Function

    Protected Overrides Function RenderPrefix(ByVal t As Table) As String
        Dim sb As New StringBuilder
        sb = sb.Append("using pixolut.BizBlox;").Append(vbCrLf).Append(vbCrLf)
        sb = sb.Append("public class ").Append(t.TableName).Append("Collection")
        sb = sb.Append(" : DOCollection").Append(vbCrLf)
        sb = sb.Append("{").Append(vbCrLf)
        Return sb.ToString()
    End Function

    Protected Overrides Function RenderPostfix(ByVal t As Table) As String
        Dim sb As New StringBuilder
        sb = sb.Append(vbCrLf)
        sb = sb.Append(vbCrLf)
        sb = sb.Append("}").Append(vbCrLf)
        Return sb.ToString()
    End Function

    Protected Overrides Function RenderColumn(ByVal t As Table, ByVal index As Integer) As String
        Return ""
    End Function

    Protected Overrides Function RenderForeignColumn(ByVal t As Table, ByVal index As Integer) As String
        Return ""
    End Function

    Protected Overrides Function RenderElements(ByVal t As Table) As String
        Dim sb As New StringBuilder
        sb = sb.Append(vbCrLf)
        sb = sb.Append("    public ").Append(t.TableName).Append("Collection").Append("() : base(new DOFactory((DataObject)new ").Append(t.TableName).Append("())) {").Append(vbCrLf)
        sb = sb.Append("    }").Append(vbCrLf)
        sb = sb.Append(vbCrLf)
        sb = sb.Append("    //to typecast your item() property").Append(vbCrLf)
        sb = sb.Append("    public new ").Append(t.TableName).Append(" this[int i]{").Append(vbCrLf)
        sb = sb.Append("        get{").Append(vbCrLf)
        sb = sb.Append("            return (").Append(t.TableName).Append(")base[i];").Append(vbCrLf)
        sb = sb.Append("        }").Append(vbCrLf)
        sb = sb.Append("    }").Append(vbCrLf)
        sb = sb.Append(vbCrLf)
        Return sb.ToString()
    End Function
End Class
